from django.db import models


class Category(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        db_table = "news_category"


class News(models.Model):
    title = models.CharField(max_length=200)
    desc = models.CharField(max_length=200)
    thumbnail = models.CharField(max_length=200)
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True)
    category = models.ForeignKey("Category", on_delete=models.SET_NULL, null=True)
    author = models.ForeignKey("xfzauth.User", on_delete=models.SET_NULL, null=True)

    class Meta:
        db_table = "news"


class Comment(models.Model):
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey("xfzauth.User", on_delete=models.CASCADE, null=True)
    news = models.ForeignKey('News', on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "news_comment"
        ordering = ["-pub_time"]

